package com.sheepone.util.io;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author Miss.杨
 * @description
 * @since 2024/10/10 - 23:32
 */
public class StreamBytesUtil {
    private StreamBytesUtil() {
    }

    private static final int BUFFER_SIZE = 1024;

    public static byte[] getBytes(InputStream is) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] buffer = new byte[BUFFER_SIZE];
        int bytesRead;
        while ((bytesRead = is.read(buffer)) != -1) {
            baos.write(buffer, 0, bytesRead);
        }
        return baos.toByteArray();
    }
}
